using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Text;
using System;
namespace NBusiness.CodeDom.Compiler
{
    [Serializable]
    public abstract class EntityElementType
    {
        private bool _isComment;
        private bool _isSignificant = true;
        private Regex _expression;

        public abstract EntityElementType[] PreviousTypes { get; }

        public bool IsSignificant { get { return _isSignificant; } }

        public bool IsComment { get { return _isComment; } }

        public Regex Expression { get { return _expression; } }

        public virtual string Name
        {
            get
            {
                string name = this.GetType().Name;
                name = name.Replace("Entity", "");
                name = name.Replace("ElementType", "");
                return name;
            }
        }

        private static EntityElementTypeUnknown _unknown = new EntityElementTypeUnknown();
        private static EntityElementTypeAny _any = new EntityElementTypeAny();
        public static EntityElementTypeUnknown Unknown
        {
            get { return _unknown; }
        }
        public static EntityElementTypeAny Any
        {
            get { return _any; }
        }

        protected EntityElementType(Regex expression, bool isSignificant)
            : this(expression, isSignificant, false)
        { }
        protected EntityElementType(Regex expression, bool isSignificant, bool isComment)
        {
            _expression = expression;
            _isSignificant = isSignificant;
            _isComment = isComment;
        }

        public override string ToString()
        {
            return Name;
        }
    }

    [Serializable]
    public class EntityElementTypeUnknown : EntityElementType
    {
        internal EntityElementTypeUnknown()
            : base(new Regex(".*"), false)
        { }

        public override EntityElementType[] PreviousTypes
        {
            get { return new EntityElementType[] { EntityElementType.Any }; }
        }
    }

    [Serializable]
    public class EntityElementTypeAny : EntityElementType
    {
        internal EntityElementTypeAny()
            : base(new Regex(".*"), false)
        { }

        public override EntityElementType[] PreviousTypes
        {
            get { return new EntityElementType[] { }; }
        }
    }
}